package au.edu.swin.swinvehicle.vehiclelicencetype;

/**
 * VehicleBooking entity
 * @version 1.0
 * @author Viet Bui,Dany Gunawan
 * @lastmodify 2009-11-05 (Dany Gunawan)
 */
import au.edu.swin.swinvehicle.eventtype.EventTypeEntity;
import au.edu.swin.swinvehicle.vehicle.VehicleEntity;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@NamedQueries({
    @NamedQuery(name = "findAllVehicleLicenceTypes",
    query = "SELECT vlt FROM VehicleLicenceTypeEntity vlt")
})
@Table(name = "VEHICLELicenceTYPE")
public class VehicleLicenceTypeEntity implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @Column(length = 15, unique = true, nullable = false)
    private String code;
    @Column(length = 63, nullable = false)
    private String description;
    @OneToMany(mappedBy = "vehicleLicenceType", cascade = CascadeType.ALL)
    private List<VehicleEntity> vehicles;
    @OneToMany(mappedBy = "vehicleLicenceType", cascade = CascadeType.ALL)
    private List<EventTypeEntity> eventTypes;

    /**
     * Default constructor
     */
    public VehicleLicenceTypeEntity() {
        vehicles = new ArrayList<VehicleEntity>();
    }

    public VehicleLicenceTypeEntity(String code, String description) {
        this(); // Call default constuctor
        setCode(code);
        setDescription(description);
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public List<VehicleEntity> getVehicles() {
        return vehicles;
    }

    public void setVehicles(List<VehicleEntity> vehicles) {
        this.vehicles = vehicles;
    }

    public List<EventTypeEntity> getEventTypes() {
        return eventTypes;
    }

    public void setEventTypes(List<EventTypeEntity> eventTypes) {
        this.eventTypes = eventTypes;
    }

    // Transfer object methods
    public VehicleLicenceTypeTO getData() {
        return new VehicleLicenceTypeTO(id, code);
    }

    public VehicleLicenceTypeDetailedTO getDetailedData() {
        return new VehicleLicenceTypeDetailedTO(id, code, description);
    }

    public void setData(VehicleLicenceTypeDetailedTO to) {
        this.setId(to.getId());
        this.setCode(to.getCode());
        this.setDescription(to.getDescription());
    }

    @Override
    public String toString() {
        return "au.edu.swin.swinvehicle.vehiclelicencetype.VehicleLicenceTypeEntity[id=" + id + "]";
    }
}
